package com.avcdata.aoscustommade.presenter;

import com.avcdata.aoscustommade.activity.ForgetFindOrChangePassword_Activity;
import com.avcdata.aoscustommade.bean.GetVerificationCodeBean;
import com.avcdata.aoscustommade.bean.VerifyNoteBean;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.model.ForgetFindOrChangePasswordModel;
import com.avcdata.aoscustommade.model.LoginActivityModel;
import com.avcdata.aoscustommade.view.ForgetFindOrChangePasswordView;

import org.json.JSONObject;

/**
 * 找回密码、修改密码的p
 * Created by zyh on 17/6/12.
 */

public class ForgetFindOrChangePasswordPresenter {
    private final ForgetFindOrChangePasswordView forgetFindOrChangePasswordView;
    private final ForgetFindOrChangePasswordModel forgetFindOrChangePasswordModel;
    private final LoginActivityModel loginActivityModel;

    public ForgetFindOrChangePasswordPresenter(ForgetFindOrChangePasswordView forgetFindOrChangePasswordView, ForgetFindOrChangePasswordModel forgetFindOrChangePasswordModel, LoginActivityModel loginActivityModel) {
        this.forgetFindOrChangePasswordView = forgetFindOrChangePasswordView;
        this.forgetFindOrChangePasswordModel = forgetFindOrChangePasswordModel;
        this.loginActivityModel = loginActivityModel;
    }

    /**
     * 验证手机号是否存在
     *
     * @param isPhone
     * @param account
     */
    public void loadCheackAccount(boolean isPhone, String account) {
        forgetFindOrChangePasswordModel.loadCheackAccount(isPhone, account, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                forgetFindOrChangePasswordView.loadCheackAccount((JSONObject) object);
            }

            @Override
            public void onFailure() {

            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 获取验证码
     *
     * @param account
     */
    public void loadCode(String account) {
        loginActivityModel.loadCode(account, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                forgetFindOrChangePasswordView.loadCodeSuccess((GetVerificationCodeBean) object);
            }

            @Override
            public void onFailure() {
                forgetFindOrChangePasswordView.loadCodeFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 验证验证码
     *
     * @param userAccount
     * @param userTextCode
     */
    public void loadCheckCode(String userAccount, String userTextCode) {
        loginActivityModel.loadCheckCode(userAccount, userTextCode, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                forgetFindOrChangePasswordView.loadCheckCodeSuccess((VerifyNoteBean) object);
            }

            @Override
            public void onFailure() {

            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 账号重置
     *
     * @param isPhone
     * @param name
     * @param password
     */
    public void loadReset(boolean isPhone, String name, String password) {
        forgetFindOrChangePasswordModel.loadReset(isPhone, name, password, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                forgetFindOrChangePasswordView.loadResetSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {

            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }
}
